home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8518 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem Negating an Unsigned Char
  5. Date: 4 Mar 1996 12:42:46 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hfkk6INN2tm@keats.ugrad.cs.ubc.ca>
  8. References: <Dnnros.Lq.0.-s@hkusuc.hku.hk> <4he27sINNdel@keats.ugrad.cs.ubc.ca> <4he5f0$acv@solutions.solon.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4he5f0$acv@solutions.solon.com>,
  12. Peter Seebach <seebs@solutions.solon.com> wrote:
  13.  >In article <4he27sINNdel@keats.ugrad.cs.ubc.ca>,
  14.  >Kazimir Kylheku <c2a192@ugrad.cs.ubc.ca> wrote:
  15.  >>To make it portable, you must manually mask for the lower eight bits:
  16.  >
  17.  >>    if (a == (~b & 0xff))
  18.  >
  19.  >Close, but the cigar yet escapes you.
  20.  
  21. No it does not. I _wanted_ eight bit arithmetic, not CHAR_BIT arithmetic.
  22.  
  23.  >    if (a == (~b & ((1 << CHAR_BIT) - 1)))
  24.  >
  25.  >Further, you can't do this portably; if sizeof(long) is 1, the
  26.  >shift is illegal.
  27.  
  28. Your shift, not mine!
  29.  
  30. I would just AND with UCHAR_MAX. I don't think there is any possibility that it
  31. could be anything other than a dyadic power, less one.
  32. -- 
  33.  
  34.